import { RouteRecordRaw } from 'vue-router';

/**
 * 建议：路由 path 路径与文件夹名称相同，找文件可浏览器地址找，方便定位文件位置
 *
 * 路由meta对象参数说明
 * meta: {
 *      title:          菜单栏及 tagsView 栏、菜单搜索名称（国际化）
 *      isLink：        是否超链接菜单，开启外链条件，`1、isLink: 链接地址不为空 2、isIframe:false`
 *      isHide：        是否隐藏此路由
 *      isKeepAlive：   是否缓存组件状态
 *      isAffix：       是否固定在 tagsView 栏上
 *      isIframe：      是否内嵌窗口，开启条件，`1、isIframe:true 2、isLink：链接地址不为空`
 *      roles：         当前路由权限标识，取角色管理。控制路由显示、隐藏。超级管理员：admin 普通角色：common
 *      icon：          菜单、tagsView 图标，阿里：加 `iconfont xxx`，fontawesome：加 `fa xxx`
 * }
 */

// 扩展 RouteMeta 接口
declare module 'vue-router' {
	interface RouteMeta {
		title?: string;
		isLink?: string;
		isHide?: boolean;
		isKeepAlive?: boolean;
		isAffix?: boolean;
		isIframe?: boolean;
		roles?: string[];
		icon?: string;
	}
}

/**
 * 定义动态路由
 * 前端添加路由，请在顶级节点的 `children 数组` 里添加
 * @description 未开启 isRequestRoutes 为 true 时使用（前端控制路由），开启时第一个顶级 children 的路由将被替换成接口请求回来的路由数据
 * @description 各字段请查看 `/@/views/system/menu/component/addMenu.vue 下的 ruleForm`
 * @returns 返回路由菜单数据
 */
export const dynamicRoutes: Array<RouteRecordRaw> = [
	{
		path: '/',
		name: '/',
		component: () => import('/@/layout/index.vue'),
		redirect: '/index',
		meta: {
			isKeepAlive: true,
		},
		children: [
			{
				path: '/index',
				name: 'home',
				component: () => import('/@/views/home/index.vue'),
				meta: {
					title: '首页',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: true,
					isIframe: false,
					roles: ['admin', 'common'],
					icon: 'ele-HomeFilled',
				},
			},
			{
				path: '/comp',
				name: '门诊',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/comp/pay',
				meta: {
					title: '门诊',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['admin', 'common'],
					icon: 'ele-Message',
				},
				children: [
					{
						path: '/pay',
						name: '门诊缴费记录',
						component: () => import('/@/views/payView/index.vue'),
						meta: {
							title: '门诊缴费记录',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin', 'common'],
						},
					},
					{
						path: '/reservation',
						name: '预约记录',
						component: () => import('/@/views/reservation.vue'),
						meta: {
							title: '预约记录',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin', 'common'],
						},
					},
				],
			},
			{
				path: '/hospital',
				name: '住院',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/hospital/hospitalpay',
				meta: {
					title: '住院',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['admin', 'common'],
					icon: 'ele-OfficeBuilding',
				},
				children: [
					{
						path: '/hospitalpay',
						name: '住院缴费记录',
						component: () => import('/@/views/hospitalView.vue'),
						meta: {
							title: '住院缴费记录',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin', 'common'],
						},
					},
					{
						path: '/room',
						name: '房间管理',
						component: () => import('/@/views/inHospital/index.vue'),
						meta: {
							title: '房间管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin', 'common'],
						},
					},
					{
						path: '/inpatient',
						name: '住院人',
						component: () => import('/@/views/inpatientView.vue'),
						meta: {
							title: '住院人',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin', 'common'],
						},
					},
				],
			},
			{
				path: '/userinfor',
				name: 'userinfor',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/userinfor/user',
				meta: {
					title: '用户管理',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['admin'],
					icon: 'ele-UserFilled',
				},
				children: [
					{
						path: '/user',
						name: '用户管理',
						component: () => import('/@/views/userinfor/user.vue'),
						meta: {
							title: '用户管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/role',
						name: '角色管理',
						component: () => import('/@/views/userinfor/role.vue'),
						meta: {
							title: '角色管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/admin',
						name: '管理员管理',
						component: () => import('/@/views/userinfor/admin.vue'),
						meta: {
							title: '管理员管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/visit',
						name: '就诊卡',
						component: () => import('/@/views/userinfor/visit.vue'),
						meta: {
							title: '就诊卡',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
				],
			},
			{
				path: '/department',
				name: 'department',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/department/departments',
				meta: {
					title: '科室管理',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['admin'],
					icon: 'ele-Collection',
				},
				children: [
					{
						path: '/departments',
						name: '科室管理项',
						component: () => import('/@/views/department.vue'),
						meta: {
							title: '科室管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
				],
			},
			{
				path: '/hospitals',
				name: '医院信息',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/hospitals/hospitalList',
				meta: {
					title: '医院信息',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['admin'],
					icon: 'ele-Menu',
				},
				children: [
					{
						path: '/hospitalList',
						name: '医院信息项',
						component: () => import('/@/views/hospitals/hospitalList.vue'),
						meta: {
							title: '医院信息',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/doctor',
						name: '医生管理',
						component: () => import('/@/views/hospitals/doctor.vue'),
						meta: {
							title: '医生管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/scheduling',
						name: '医生排班管理',
						component: () => import('/@/views/hospitals/scheduling.vue'),
						meta: {
							title: '医生排班管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/label',
						name: '标签管理',
						component: () => import('/@/views/hospitals/label.vue'),
						meta: {
							title: '标签管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/drug',
						name: '药品管理',
						component: () => import('/@/views/hospitals/drug.vue'),
						meta: {
							title: '药品管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/physical',
						name: '体检管理',
						component: () => import('/@/views/hospitals/physical.vue'),
						meta: {
							title: '体检管理',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
					{
						path: '/trends',
						name: '医院动态',
						component: () => import('/@/views/hospitals/trends.vue'),
						meta: {
							title: '医院动态',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['admin'],
						},
					},
				],
			},
		],
	},
];

/**
 * 定义404、401界面
 * @link 参考：https://next.router.vuejs.org/zh/guide/essentials/history-mode.html#netlify
 */
export const notFoundAndNoPower = [
	{
		path: '/:path(.*)*',
		name: 'notFound',
		component: () => import('/@/views/error/404.vue'),
		meta: {
			title: '找不到此页面',
			isHide: true,
		},
	},
	{
		path: '/401',
		name: 'noPower',
		component: () => import('/@/views/error/401.vue'),
		meta: {
			title: '没有权限',
			isHide: true,
		},
	},
];

/**
 * 定义静态路由（默认路由）
 * 此路由不要动，前端添加路由的话，请在 `dynamicRoutes 数组` 中添加
 * @description 前端控制直接改 dynamicRoutes 中的路由，后端控制不需要修改，请求接口路由数据时，会覆盖 dynamicRoutes 第一个顶级 children 的内容（全屏，不包含 layout 中的路由出口）
 * @returns 返回路由菜单数据
 */
export const staticRoutes: Array<RouteRecordRaw> = [
	{
		path: '/login',
		name: 'login',
		component: () => import('/@/views/login/index.vue'),
		meta: {
			title: '登录',
		},
	},
];